package util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.content.Context;
import android.os.Environment;
import android.util.Log;

public class ReadWrite {
    /** Called when the activity is first created. */
    
	File stilling;
	
	static long nu = System.currentTimeMillis();
	public static int byteHentetOverNetvaerk = 0;
	
        public void filcache(Context context){
        
//        init();
        }
	
	public static void init(String web, String filnavn) {
		 try {
	            File root = Environment.getExternalStorageDirectory() ;
	            
	          
	            URL u = new URL(web); 
	            HttpURLConnection c = (HttpURLConnection) u.openConnection();
	            c.setRequestMethod("GET");
	            c.setDoOutput(true);
	            c.connect();
	            Log.d("nyFilHentning", "laver forbindelse til sdkort");
	            FileOutputStream f = new FileOutputStream(new File(root + "/StadionApp", filnavn));
	            System.out.println("init " + f);
	            InputStream in = c.getInputStream();
	            Log.d("nyFilHentning", "så er filen hentet og placeret  på sdkortet");
	            byte[] buffer = new byte[1024];
	            int len1 = 0;
	            while ((len1 = in.read(buffer)) > 0) {
	                f.write(buffer, 0, len1);
	            }
	            f.close();
	        } catch (Exception e) {
	            Log.d("Downloader", e.getMessage()+ " - øøøh hvad for en fisk");
	        }
	}
}

